﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Buffalo.Lib.Common" %>
<%@ Import Namespace="Buffalo.SMECommon.DAL.Models" %>
<%@ Import Namespace="Buffalo.SMECommon.DAL" %>
<%@ Import Namespace="Buffalo.Web.Areas.SMECommon" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <ext:XScript ID="XScript1" runat="server">

    <script type="text/javascript">
        var openUploadImageHandler = function () {
            AppGeneral.addTab({ title: 'Upload image', url: '/Areas/SMECommon/Pages/UploadImageView.aspx', icon: 'Form' });

        };

    </script>
    </ext:XScript>
    <script runat="server">
        protected void UploadImageClick(object sender, DirectEventArgs e)
        {
            if (this.filUploadImage.HasFile)
            {
                string imageFile = this.filUploadImage.PostedFile.FileName;
                if (!(imageFile.ToLower().EndsWith(".jpg") || imageFile.ToLower().EndsWith(".png") || imageFile.ToLower().EndsWith(".bmp")))
                {
                    ShowMessage("Error", "File type is not valid!", MessageBox.Icon.ERROR);
                    return;
                }
                string connectionString = ConfigurationManager.ConnectionStrings[GeneralConstant.CONNECTION_STRING].ConnectionString;
                X.Msg.Show(new MessageBoxConfig
                {
                    Buttons = MessageBox.Button.OK,
                    Icon = MessageBox.Icon.INFO,
                    Title = "Success",
                    Message = string.Format("Imported file: {0}", imageFile)
                });
                string excelFullFile = string.Format(@"{0}\Temp\{1}", CommonManager.GetModuleFolder(), imageFile);
                filUploadImage.PostedFile.SaveAs(excelFullFile);
            }
            else
            {
                ShowMessage("Error", "Import fail", MessageBox.Icon.ERROR);
            }
        }
        private void ShowMessage(string title, string message, MessageBox.Icon icon)
        {
            X.Msg.Show(new MessageBoxConfig
            {
                Buttons = MessageBox.Button.OK,
                Icon = icon,
                Title = title,
                Message = message
            });
        }
    </script>
</head>
<body>
    <ext:ResourceManager ID="ResourceManager1" runat="server">
    </ext:ResourceManager>
    <form id="Form1" runat="server">
    <ext:Viewport ID="mainViewPort" runat="server" Layout="fit">
        <Items>
            <ext:Panel ID="Panel1" runat="server" Border="false" Layout="fit">
<%--                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:Button ID="btnClose" runat="server" Text="Close" Icon="DoorOut">
                                <Listeners>
                                    <Click Handler="parent.ImportExcelWindow.hide();" />
                                </Listeners>
                            </ext:Button>
                            <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                        </Items>
                    </ext:Toolbar>
                </TopBar>--%>
                <Items>
                    <ext:TabPanel ID="TourTabPanel" runat="server" Border="false" LayoutOnTabChange="true">
                        <Items>
                            <ext:Panel ID="panTourInfo" runat="server" Title="Tour Info" Padding="6" Layout="fit">
                                <Items>
                                    <ext:FormPanel ID="ImportExcelForm" runat="server" Border="false">
                                        <Items>
                                            <ext:Container ID="Container1" runat="server" Flex="1">
                                                <Items>
                                                    <ext:FileUploadField ID="filUploadImage" runat="server" Width="300" Icon="Attach"
                                                        EmptyText="Select an Image file" />
                                                    <ext:Button ID="btnUpload" runat="server" Text="Upload">
                                                        <DirectEvents>
                                                            <Click OnEvent="UploadImageClick">
                                                            </Click>
                                                        </DirectEvents>
                                                    </ext:Button>
                                                </Items>
                                            </ext:Container>
                                        </Items>
                                    </ext:FormPanel>
                                </Items>
                            </ext:Panel>
                        </Items>
                    </ext:TabPanel>
                </Items>
            </ext:Panel>
        </Items>
    </ext:Viewport>
    </form>
</body>
</html>
